/*******************************************
 * Copyright 2007 Aphrodite Framework for javaME .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * Email : owner@aphroditeme.dev.java.net
 * Contributors:
 *     Kent Elton - initial API and implementation
 *******************************************/

package com.aphrodite.ui.bg;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

import com.aphrodite.util.StringUtil;

/**
 * Text is wrapped and rendered as a widget background
 * 
 * @author kentelt
 * 
 */
public class TextBackground extends Background {
	private Font font = Font.getDefaultFont();
	private int fontColor = 0x000000;
	private String text;

	public TextBackground(String text) {
		super();
		this.text = text;
	}

	public void render(Graphics g) {
		String[] lines = StringUtil.doTextWrap(this.text, font, width - 4, width - 4);
		g.setColor(fontColor);
		g.setFont(font);
		for (int i = 0; i < lines.length; i++) {
			g.drawString(lines[i], x + 2, y + (font.getHeight() * i) + 2, 0);
		}
	}

	public void setFont(Font font) {
		this.font = font;
	}

	public void setFontColor(int color) {
		this.fontColor = color;
	}

	public void setText(String text) {
		this.text = text;
	}
}
